package com.zhiyou100.service.imp;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zhiyou100.IService.IUserService;
import com.zhiyou100.entity.prosGo.TbUser;
import com.zhiyou100.entity.prosGo.TbUserExample;
import com.zhiyou100.entity.prosGo.TbUserExample.Criteria;
import com.zhiyou100.mapper.prosGo.TbUserMapper;

@Service("userService")
public class UserService implements IUserService{

	//注入mapper对象
	@Resource
	private TbUserMapper tbUserMapper;

	public Integer addUser(TbUser tbUser) {
		
		
		int list = tbUserMapper.insert(tbUser);
		
		return list;
	}

	public TbUser login(TbUser tbUser) {
        TbUserExample tbUserExample=new TbUserExample();
        Criteria criteria = tbUserExample.createCriteria();
        criteria.andUsPhoneEqualTo(tbUser.getUsPhone());
        criteria.andUsPasswordEqualTo(tbUser.getUsPassword());
        return tbUserMapper.selectByExample(tbUserExample).size()>0?tbUserMapper.selectByExample(tbUserExample).get(0):null;
    }
	public Integer autoym(TbUser tbUser) {
		TbUserExample tbUserExample = new TbUserExample();
		Criteria criteria = tbUserExample.createCriteria();
		criteria.andUsPhoneEqualTo(tbUser.getUsPhone());
		List<TbUser> list = tbUserMapper.selectByExample(tbUserExample);
		
		TbUser tbUsers = null;
		if(list.size()>0) 
			tbUsers=list.get(0);
			tbUsers.setUsRealname(tbUser.getUsRealname());
			tbUsers.setUsIdcard(tbUser.getUsIdcard());
			System.out.println(tbUsers.toString());
			return tbUserMapper.updateByPrimaryKeySelective(tbUsers)>0?1:2;
		
	}
}